<?php

namespace common\models\Cases;

use Yii;

/**
 * This is the model class for table "cases".
 *
 * @property string $id
 * @property string $name 案例名
 * @property string $url 案例链接地址
 * @property string $content 案例介绍内容
 * @property string $picture 案例上传图
 * @property int $status 状态
 * @property string $create_at 上传时间
 * @property string $update_at 新更时间
 */
class Cases extends \common\models\BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'cases';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'content', 'picture'], 'required'],
            [['content'], 'string'],
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['status'], 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE]],
            [['name', 'url'], 'string', 'max' => 255],
            [['picture'], 'validatePicture'],
        ];
    }

    public function validatePicture($atrribut, $params)
    {
        $imgStr = implode(',', (array)$this->picture);
        if (empty($imgStr)){
            return $this->addError('picture', '请上传案例图片');
        }
        $this->picture = $imgStr;
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '案例标题',
            'url' => '案例链接地址',
            'content' => '案例介绍内容',
            'picture' => '案例上传图',
            'status' => '状态',
            'created_at' => '上传时间',
            'updated_at' => '新更时间',
        ];
    }
}
